import React, { memo, useEffect } from "react";
import { useDispatch, useSelector, shallowEqual } from "react-redux";
import { useHistory } from "react-router-dom";
import Recommend from "./recommend";
import Barticle from "./barticle";
import Blogs from "./blogs";
import Useless from "./useless";
import Threemess from "./threemess";
import Populartags from "./populartags";
import { Mainwrap } from "./style";

import { getallblogactionasync } from "../store/actioncreater";
// import "http://www.lmlblog.com/winter/templets/xq/js/snowy.js";
export default memo(function Main() {
  // useEffect(() => {
  //   if (!localStorage.getItem("snow")) {
  //     window.location.reload();
  //     localStorage.setItem("snow", 1);
  //   }
  //   return () => {
  //     localStorage.removeItem("snow");
  //   };
  // }, []);
  const dispatch = useDispatch();
  const history = useHistory();
  useEffect(() => {
    dispatch(getallblogactionasync(-1));
  }, [dispatch]);
  const { blog } = useSelector(
    (store) => ({
      blog: store.newhomestore.blog,
    }),
    shallowEqual
  );
  return (
    <Mainwrap>
      <div className="left">
        <Recommend blog={blog}></Recommend>
        <Barticle blog={blog}></Barticle>
        <Blogs blog={blog}></Blogs>
      </div>
      <div className="right">
        <Useless></Useless>
        <Threemess blog={blog}></Threemess>
        <Populartags></Populartags>
      </div>
      <div className="tologin" onClick={(e) => history.push("/")}>
        退出登录
      </div>
    </Mainwrap>
  );
});
